package com.bw.contrller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.bean.DataBean;
import com.bw.service.Dataservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 徐金浩
 * @date 2025年10月13日 10:03
 */
@RestController
public class DataController {
    @Autowired
    private Dataservice dataservice;


    @RequestMapping("s1")
    public JSONObject s1()
    {
        JSONObject result = new JSONObject();
        result.put("status",0);
        result.put("msg","");

        DataBean dataBean = dataservice.select1();
        result.put("data",dataBean.getCta());


        return result;
    }
    @RequestMapping("s2")
    public JSONObject s2() {
        JSONObject result = new JSONObject();
        result.put("status", 0);
        result.put("msg", "");

        JSONArray data = new JSONArray();
        result.put("data",data);

        List<DataBean> beans = dataservice.select2();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getCta());
            row.put("value",bean.getCtb());

            data.add(row);
        }

        return result;
    }

    @RequestMapping("s3")
    public JSONObject s3() {
        JSONObject result = new JSONObject();
        result.put("status", 0);
        result.put("msg", "");

        JSONObject data = new JSONObject();
        result.put("data", data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();
        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject c1 = new JSONObject();
        c1.put("name","考试人次");
        c1.put("id","name");

        JSONObject c2 = new JSONObject();
        c2.put("name","平均分");
        c2.put("id","cta");

        JSONObject c3 = new JSONObject();
        c3.put("name","平均时长");
        c3.put("id","ctb");

        columns.add(c1);
        columns.add(c2);
        columns.add(c3);

        List<DataBean> beans = dataservice.select3();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getCta());
            row.put("value",bean.getCtb());

            rows.add(row);
        }

        return result;
    }

    @RequestMapping("4")
    public JSONObject s4() {
        JSONObject result = new JSONObject();
        result.put("status", 0);
        result.put("msg", "");

        JSONObject data = new JSONObject();
        result.put("data", data);

        JSONArray mapData = new JSONArray();
        JSONArray tooltipNames = new JSONArray();
        JSONArray tooltipUnits = new JSONArray();
        data.put("tooltipUnits",tooltipUnits);
        data.put("tooltipNames",tooltipNames);
        data.put("mapData",mapData);

        List<DataBean> beans = dataservice.select4();
        for (DataBean bean : beans) {
            JSONObject row = new JSONObject();
            row.put("name",bean.getName());
            row.put("value",bean.getCta());
            JSONArray tooltipValues = new JSONArray();
            tooltipValues.add(bean.getCtb());
            row.put("tooltipValues",tooltipValues);

            mapData.add(row);
        }

        tooltipNames.add("总额");

        tooltipUnits.add("人");



        return result;
    }

}
